<?php
$link = mysql_connect('localhost','cs4350','!@'); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysql_error()); 
}
else {
    echo 'You are connected to the cs4350 database server!</br>';
}
if (!mysql_select_db( 'todo', $link)) {
    die('Aw snap, no database named todo...');
}
else {
    echo 'You are now using the todo database!</br>';
}

$sql = "INSERT INTO list VALUES ('$_POST[username]','$_POST[taskName]','$_POST[taskDesc]','false',CURDATE(), 'Auto_increment', '$_POST[lat]','$_POST[long]')";
//die($sql);

$test = 'SELECT * FROM list';

$result = mysql_query($sql, $link);
$testResult = mysql_query($test, $link);

if (!$result) {
	die($sql);
//    die('Invalid query: ' . mysql_error());
}
else {
    // print_r($result);
    // var_dump($result);
    
	//echo 'Task added </br>';	//change to redirect or reload later
	header('location:view.php?user='.$_POST["username"]);
	
    mysql_free_result($result);
	mysql_free_result($testResult);
}
?>